// https://www.acwing.com/problem/content/828/

#include <iostream>
#include <vector>

using namespace std;

constexpr int ARRAY_MAX_SIZE = 100010;

struct ListNode {
    int value;
    int next_index;
};

ListNode all_nodes[ARRAY_MAX_SIZE];

int head;

int idx;

void init() {
    head = -1;
    idx = 0;
}

void push_front(int x) {
    all_nodes[idx].value = x;
    all_nodes[idx].next_index = head;
    head = idx;
    idx++;
}

void insert(int k, int x) {
    // 1. 记录值
    all_nodes[idx].value = x;
    // 2. 移动指针
    all_nodes[idx].next_index= all_nodes[k].next_index;
    // 3. 插入位置
    all_nodes[k].next_index = idx;
    // 4. 增加下个结点的位置
    idx++;
}

void remove(int k) {
    all_nodes[k].next_index = all_nodes[all_nodes[k].next_index].next_index;
}

int main() {
    int n;
    cin>>n;
    init();

    char ch;
    int x, k;
    while (n-->0) {
        cin>>ch;
        if (ch == 'H') {
            cin>>x;
            push_front(x);
        } else if (ch == 'I') {
            cin>>k>>x;
            insert(k-1, x);
        } else if (ch == 'D') {
            cin>>k;
            if (k == 0) {
                head = all_nodes[head].next_index;
            } else  {
                remove(k - 1);
            }
        }
    }

    for (int i=head; i != -1; i = all_nodes[i].next_index) {
        cout<<all_nodes[i].value<<" ";
    }
    cout<<endl;
    return 0;
}
